package com.redpack.redpost.struts.action.admin;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.redpack.redpost.util.to.generalUtil;


public class login extends Action {
	
	public ActionForward execute(
			ActionMapping mapping, 
			ActionForm form, 
			HttpServletRequest request, 
			HttpServletResponse response) throws Exception {
		
		boolean logginVal = generalUtil.isLoggedInAdmin(request);
		if(logginVal!=true){
			return mapping.findForward("noLogin") ;
		}
			
		HttpSession session = request.getSession();
		
		String salida = "";
		if(session.getAttribute("tipousuario").equals("1")){
			salida = "success";
		}
		if(session.getAttribute("tipousuario").equals("2")){
			salida = "success2";
		}
		
		String salir = "0";
		if( request.getParameter("salir") != null ){
			salir = request.getParameter("salir");
			request.getSession().removeAttribute("UserLogin");
		}
		
		if( salir.equals("1") ){
			session.removeAttribute("UserLogin");
			request.getSession().removeAttribute("UserLogin");
		}

		return mapping.findForward(salida) ;
	}

}
